package IOStream;

/*
 * Author: JacksonCoder
 * FileName: CharStreamCopyFile
 * Version: 1.0.0
 * Date: 2025/2/26
 */

import java.io.*;

public class CharStreamCopyFile {

    public static void main(String[] args) {
        String sourceFilePath = "source.txt"; // 源文件路径
        String destinationFilePath = "destination.txt"; // 目标文件路径


        // 使用 try-with-resources 自动关闭流
        try (FileReader fr = new FileReader(sourceFilePath);
             FileWriter fw = new FileWriter(destinationFilePath);
             BufferedReader br = new BufferedReader(fr);
             BufferedWriter bw = new BufferedWriter(fw);
        ) {
            String line;
            // 逐行读取并输入
            while ((line = br.readLine()) != null) {
                bw.write(line);
                bw.newLine(); // 写入换行符
            }

            System.out.println("文件复制完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
